package com.mycrawler;

import org.jsoup.nodes.Document;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.selector.Html;



public class JsoupPageProcessor implements PageProcessor {
    @Override
    public void process(Page page) {
        Html html = page.getHtml();
        Document document = html.getDocument();
        String title = document.getElementsByTag("title").text();
        page.putField("title",title);
    }

    @Override
    public Site getSite() {
        return Site.me();
    }


    public static void main(String[] args) {
        Spider.create(new JsoupPageProcessor()).addUrl("https://www.jd.com").start();
    }
}
